package com.dreamsky.life.model;

import java.util.List;

import com.jfinal.plugin.activerecord.Model;

/**
 * 电器控制模型
 * 
 * @author David
 * 
 */
public class ElectricControl extends Model<ElectricControl> {

	public static ElectricControl dao = new ElectricControl();

	/**
	 * 得到用户电器的控制动作信息
	 * 
	 * @param userId
	 * @return
	 */
	public List<ElectricControl> getUserElectricControll(String userId) {
		StringBuffer sql = new StringBuffer();
		sql.append("SELECT id, ele_id, cl_employ, cl_time                  ");
		sql.append("FROM lf_ele_control                                    ");
		sql.append("WHERE (ele_id, cl_time) IN (SELECT ele_id, MAX(cl_time)");
		sql.append("	FROM lf_ele_control                                ");
		sql.append("	WHERE re_employ IS NULL                            ");
		sql.append("		AND cl_time > curdate()                        ");
		sql.append("		AND user_id = ?                                ");
		sql.append("	GROUP BY ele_id)                                   ");

		return this.find(sql.toString(), userId);
	}

}
